USE [master]
GO
/****** Object:  Database [Bastanteo]    Script Date: 11/19/2011 01:06:48 ******/
CREATE DATABASE [Bastanteo]
GO
ALTER DATABASE [Bastanteo] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [Bastanteo].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [Bastanteo] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [Bastanteo] SET ANSI_NULLS OFF
GO
ALTER DATABASE [Bastanteo] SET ANSI_PADDING OFF
GO
ALTER DATABASE [Bastanteo] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [Bastanteo] SET ARITHABORT OFF
GO
ALTER DATABASE [Bastanteo] SET AUTO_CLOSE ON
GO
ALTER DATABASE [Bastanteo] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [Bastanteo] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [Bastanteo] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [Bastanteo] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [Bastanteo] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [Bastanteo] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [Bastanteo] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [Bastanteo] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [Bastanteo] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [Bastanteo] SET  ENABLE_BROKER
GO
ALTER DATABASE [Bastanteo] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [Bastanteo] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [Bastanteo] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [Bastanteo] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [Bastanteo] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [Bastanteo] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [Bastanteo] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [Bastanteo] SET  READ_WRITE
GO
ALTER DATABASE [Bastanteo] SET RECOVERY SIMPLE
GO
ALTER DATABASE [Bastanteo] SET  MULTI_USER
GO
ALTER DATABASE [Bastanteo] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [Bastanteo] SET DB_CHAINING OFF
GO
USE [Bastanteo]
GO
/****** Object:  Table [dbo].[Poder]    Script Date: 11/19/2011 01:06:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Poder](
	[CodigoPoder] Int NOT NULL,
	[Descripcion] [varchar](70) NOT NULL,
	[TipoProducto] [varchar](25) NOT NULL,
 CONSTRAINT [PK_CodigoPoder] PRIMARY KEY CLUSTERED 
(
	[CodigoPoder] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Grupo]    Script Date: 11/19/2011 01:06:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Grupo](
	[CodigoGrupo] Int NOT NULL,
	[Descripcion] [varchar](70) NOT NULL,
 CONSTRAINT [PK_CodigoGrupo] PRIMARY KEY CLUSTERED 
(
	[CodigoGrupo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Cliente]    Script Date: 11/19/2011 01:06:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Cliente](
	[CodigoCliente] Int NOT NULL,
	[RazonSocial] [varchar](200) NOT NULL,
	[Ruc] [varchar](11) NOT NULL,
	[FechaInicioOperaciones] [datetime] NOT NULL,
	[TipoEmpresa] [varchar](3) NOT NULL,
	[CantidadEmpleados] [decimal](5, 0) NOT NULL,
 CONSTRAINT [PK_CodigoCliente] PRIMARY KEY CLUSTERED 
(
	[CodigoCliente] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Representante]    Script Date: 11/19/2011 01:06:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Representante](
	[CodigoRepresentante] Int NOT NULL,
	[TipoDocumento] [varchar](3) NOT NULL,
	[NumeroDocumento] [varchar](15) NOT NULL,
	[CodigoCliente] Int NOT NULL,
	[Nombres] [varchar](100) ,
	[Apellidos] [varchar](100) ,
	[Cargo] [varchar](20) ,
	[CodigoGrupo] Int NOT NULL,
 CONSTRAINT [PK_Representante] PRIMARY KEY CLUSTERED 
(
	[CodigoRepresentante] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Bastanteo]    Script Date: 11/19/2011 01:06:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Bastanteo](
	[CodigoBastanteo] Int NOT NULL,
	[CodigoGrupo] Int NOT NULL,
	[CodigoPoder] Int NOT NULL,
	[ImporteLimite] [decimal](16, 4) ,
	[FechaVencimiento] Datetime ,
	[TipoIntervencion] [varchar](1) ,
 CONSTRAINT [PK_Bastanteo] PRIMARY KEY CLUSTERED 
(
	[CodigoBastanteo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[BastanteoCombinacion]    Script Date: 11/19/2011 01:06:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[BastanteoCombinacion](
	[CodigoBastanteoCombinacion] Int NOT NULL,
	[CodigoBastanteo] Int NOT NULL,
	[CodigoGrupo] Int NOT NULL,
 CONSTRAINT [PK_BastanteoCombinacion] PRIMARY KEY CLUSTERED 
(
	[CodigoBastanteoCombinacion] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  ForeignKey [FK_ClienteRepresentante]    Script Date: 11/19/2011 01:06:51 ******/
ALTER TABLE [dbo].[Representante]  WITH CHECK ADD  CONSTRAINT [FK_ClienteRepresentante] FOREIGN KEY([CodigoCliente])
REFERENCES [dbo].[Cliente] ([CodigoCliente])
GO
ALTER TABLE [dbo].[Representante] CHECK CONSTRAINT [FK_ClienteRepresentante]
GO
/****** Object:  ForeignKey [FK_RepresentanteGrupo]    Script Date: 11/19/2011 01:06:51 ******/
ALTER TABLE [dbo].[Representante]  WITH CHECK ADD  CONSTRAINT [FK_RepresentanteGrupo] FOREIGN KEY([CodigoGrupo])
REFERENCES [dbo].[Grupo] ([CodigoGrupo])
GO
ALTER TABLE [dbo].[Representante] CHECK CONSTRAINT [FK_RepresentanteGrupo]
GO
/****** Object:  ForeignKey [FK_BastanteoGrupo]    Script Date: 11/19/2011 01:06:51 ******/
ALTER TABLE [dbo].[Bastanteo]  WITH CHECK ADD  CONSTRAINT [FK_BastanteoGrupo] FOREIGN KEY([CodigoGrupo])
REFERENCES [dbo].[Grupo] ([CodigoGrupo])
GO
ALTER TABLE [dbo].[Bastanteo] CHECK CONSTRAINT [FK_BastanteoGrupo]
GO
/****** Object:  ForeignKey [FK_BastanteoPoder]    Script Date: 11/19/2011 01:06:51 ******/
ALTER TABLE [dbo].[Bastanteo]  WITH CHECK ADD  CONSTRAINT [FK_BastanteoPoder] FOREIGN KEY([CodigoPoder])
REFERENCES [dbo].[Poder] ([CodigoPoder])
GO
ALTER TABLE [dbo].[Bastanteo] CHECK CONSTRAINT [FK_BastanteoPoder]
GO
/****** Object:  ForeignKey [FK_BastanteoCombinacion]    Script Date: 11/19/2011 01:06:51 ******/
ALTER TABLE [dbo].[BastanteoCombinacion]  WITH CHECK ADD  CONSTRAINT [FK_BastanteoCombinacion] FOREIGN KEY([CodigoBastanteo])
REFERENCES [dbo].[Bastanteo] ([CodigoBastanteo])
GO
ALTER TABLE [dbo].[BastanteoCombinacion] CHECK CONSTRAINT [FK_BastanteoCombinacion]
GO
/****** Object:  ForeignKey [FK_BastanteoCombinacionGrupo]    Script Date: 11/19/2011 01:06:51 ******/
ALTER TABLE [dbo].[BastanteoCombinacion]  WITH CHECK ADD  CONSTRAINT [FK_BastanteoCombinacionGrupo] FOREIGN KEY([CodigoGrupo])
REFERENCES [dbo].[Grupo] ([CodigoGrupo])
GO
ALTER TABLE [dbo].[BastanteoCombinacion] CHECK CONSTRAINT [FK_BastanteoCombinacionGrupo]
GO
